package com.example.mapper;

import com.example.pojo.News;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface NewsMapper {

    /**
     * 查询全部新闻列表
     * @return
     */
    @Select("select * from news")
    List<News> list();

    /**
     * 新增一条新闻
     * @param news
     */
    @Insert("insert into news(news_title, news_content, type_id, type_name, news_publishers, pub_time, news_pic, news_rate) " +
            "values(#{newsTitle},#{newsContent},#{typeId},#{typeName},#{newsPublishers},#{pubTime},#{newsPic},#{newsRate})")
    void add(News news);

    /**
     * 根据Id删除一条新闻
     * @param newsId
     */
    @Delete("delete from news where news_id = #{newsId}")
    void deleteById(Integer newsId);

    @Update("insert into pics(url) values(#{path})")
    void uploadPic(String path);

    @Select("select * from pics")
    String[] picsList();

    @Delete("TRUNCATE TABLE pics;")
    void deletePic();
}
